package com.boot.core.exception;

/**
 * @author 霜寒 <1621856595@qq.com>
 * @description 错误类
 * @date 2023/3/8 21:06
 **/

public class ExceptionUtils {
    /**
     * 提取真正的异常
     */
    public static Throwable unwrap(Throwable throwable) {
        if (throwable instanceof WrappedRuntimeException) {
            if (throwable.getCause() != null) {
                return throwable.getCause();
            }
        }
        return throwable;
    }

    public static RuntimeException wrap(String message, Throwable throwable) {
        if (throwable instanceof RuntimeException) {
            return (RuntimeException) throwable;
        }
        return new WrappedRuntimeException(message, throwable);
    }

}
